package org.song.exception.result;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class AjaxResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public AjaxResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public AjaxResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }



    public static<T> AjaxResult<T> success() {
        return success(null);
    }

    public static<T> AjaxResult<T> exception() {
        return new AjaxResult<>(ResultEnum.Exception.getCode(),ResultEnum.Exception.getMsg());
    }

    public static<T> AjaxResult<T> exception( String msg ) {
        return new AjaxResult<>(ResultEnum.Exception.getCode(),msg);
    }

    public static<T> AjaxResult<T> successMsg(String msg) {
        return new AjaxResult<>(ResultEnum.SUCCESS.getCode(),msg,null);
    }


    public static<T> AjaxResult<T> success(T data) {
        return new AjaxResult<>(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),data);
    }

    public static<T> AjaxResult<T> failed() {
        return new AjaxResult<>(ResultEnum.FAILED.getCode(), ResultEnum.FAILED.getMsg());
    }

    public static<T> AjaxResult<T> failed(String msg) {
        return new AjaxResult<>(ResultEnum.FAILED.getCode(), msg);
    }

    /**
     *  权限不足返回的 JSON
     * @param msg
     * @param <T>
     * @return
     */
    public static<T> AjaxResult<T> noPermission(String msg) {
        return new AjaxResult<>(ResultEnum.NO_PERMISSION.getCode(), msg);
    }

    public static<T> AjaxResult<T> noPermission() {
        return noPermission(null);
    }

    public static<T> AjaxResult<T> insufficientIdentity(String msg) {
        return new AjaxResult<>(ResultEnum.INSUFFICIENT_IDENTITY.getCode(), msg);
    }

    public static<T> AjaxResult<T> insufficientIdentity() {
        return insufficientIdentity(null);
    }



}
